﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AudioCore.Entity;
using AudioCore.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;

namespace AudioCore.DAO
{
    public class CategoryDao : BaseDao
    {
        internal CategoryDao()
            : base("Category", "CategoryID")
        {
            db = DatabaseFactory.CreateDatabase(Constant.DATABASE);
        }

        internal DataTable GetAllCategory()
        {
            return SelectAllItem();
        }

        internal DataTable GetCategoryByParentID(int parentID)
        {
            return SelectEntityByColumnName("ParentID", parentID);
        }

        internal bool HasArticle(int categoryID)
        {
            string query = "select top 1 CategoryID from Category where CategoryID = {0}";
            query = string.Format(query,categoryID);
            int count = db.ExecuteDataSet(CommandType.Text,query).Tables[0].Rows.Count;
            return count > 0;
        }

        #region Method for service

        internal DataTable GetCategory(int parentID)
        {
            object[] param = new object[] { parentID };
            return db.ExecuteDataSet("sp_AUDIO_GetCategory", param).Tables[0];
        }

        #endregion
    }
}
